<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // const arr = 'web前端开发';
        // const reg = /web/;
        // // 检测是否匹配
        // console.log(reg.test(arr));
        // // 获取匹配项
        // console.log(reg.exec(arr));//获取匹配项返回一个数组
        // console.log('--------------------');
        // //元字符
        //1.边界符
        console.log(/^二哈/.test("二哈"));//true
        console.log(/^二哈/.test("二哈二哈"));//true
        console.log(/^二哈$/.test('二哈'));//true
        console.log(/^二哈$/.test('二哈二哈'));//false
        console.log('------------------------------------');
        // 2.量词
        // * 出现 >=0 次
        console.log(/^哈*$/.test('二哈'));//flase
        console.log(/^哈*$/.test(''));//true
        console.log(/^哈*$/.test('哈'));//true
        console.log(/^哈*$/.test('哈哈'));//true
        console.log(/^哈*$/.test('哈哈哈'));//true
        console.log(/^哈*$/.test('哈哈哈哈'));//true
        console.log(/^哈*$/.test('哈哈哈哈哈'));//true
        console.log('-------------------------------');
        // + 重复出现 >=1 次
        console.log(/^哈+$/.test('二哈'));//flase
        console.log(/^哈+$/.test(''));//flase
        console.log(/^哈+$/.test('哈'));//true
        console.log(/^哈+$/.test('哈哈'));//true
        console.log(/^哈+$/.test('哈哈哈'));//true
        console.log(/^哈+$/.test('哈哈哈哈'));//true
        console.log(/^哈+$/.test('哈哈哈哈哈'));//true
        console.log('-------------------------------');
        // ? 出现 1 || 0
        console.log(/^哈?$/.test('二哈'));//flase
        console.log(/^哈?$/.test(''));//true
        console.log(/^哈?$/.test('哈'));//true
        console.log(/^哈?$/.test('哈哈'));//flase
        console.log(/^哈?$/.test('哈哈哈'));//flase
        console.log(/^哈?$/.test('哈哈哈哈'));//flase
        console.log(/^哈?$/.test('哈哈哈哈哈'));//flase
        console.log('-------------------------------');
        // {n} 出现 n次
        console.log(/^哈{3}$/.test('二哈'));//flase
        console.log(/^哈{3}$/.test(''));//flase
        console.log(/^哈{3}$/.test('哈'));//flase
        console.log(/^哈{3}$/.test('哈哈'));//flase
        console.log(/^哈{3}$/.test('哈哈哈'));//true
        console.log(/^哈{3}$/.test('哈哈哈哈'));//flase
        console.log(/^哈{3}$/.test('哈哈哈哈哈'));//flase
        // {n,} 出现 >=n次
        console.log(/^哈{3,}$/.test('二哈'));//flase
        console.log(/^哈{3,}$/.test(''));//flase
        console.log(/^哈{3,}$/.test('哈'));//flase
        console.log(/^哈{3,}$/.test('哈哈'));//flase
        console.log(/^哈{3,}$/.test('哈哈哈'));//true
        console.log(/^哈{3,}$/.test('哈哈哈哈'));//true
        console.log(/^哈{3,}$/.test('哈哈哈哈哈'));//true
        // {n,m} 出现 >=n && <=m 次
        console.log(/^哈{3,6}$/.test('二哈'));//flase
        console.log(/^哈{3,6}$/.test(''));//flase
        console.log(/^哈{3,6}$/.test('哈'));//flase
        console.log(/^哈{3,6}$/.test('哈哈'));//flase
        console.log(/^哈{3,6}$/.test('哈哈哈'));//true
        console.log(/^哈{3,6}$/.test('哈哈哈哈'));//true
        console.log(/^哈{3,6}$/.test('哈哈哈哈哈'));//true
        // 字符类
        // [abc]只选其中一个
        console.log(/^[abc]$/.test('a'));//true
        console.log(/^[abc]$/.test('b'));//true
        console.log(/^[abc]$/.test('c'));//true
        console.log(/^[abc]$/.test('ab'));//flase
        // [a-z]只选小写字母中的一个
        console.log(/^[a-z]$/.test('a'));//true
        console.log(/^[a-z]$/.test('b'));//true
        console.log(/^[a-z]$/.test('c'));//true
        console.log(/^[a-z]$/.test('ab'));//flase
        // /^[a-zA-Z0-9-_]{6,16}$/
    </script>
</body>

</html>